home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '88 / Hacks '88 / Holey / nuHoley.p < prev    next >
Text File  |  1988-06-23  |  3KB  |  144 lines

  1. (*    This is an FKEY that empties the content region of all
  2.     the windows in a layer.  This is useful under MultiFinder
  3.     because you can select icons that might be covered up,
  4.     once all the windows above it become "transparent".
  5.     
  6.     It is a simple variation of the technique described by Greg 
  7.     Marriott in the Oct 87 MacTutor.  It works by modifying
  8.     the strucRgn and contRgn of all the windows, which is a very
  9.     bad thing to do, especially under MultiFinder (where this
  10.     FKEY is most useful.  This puts the FKEY into the category of
  11.     extra-slimey hacks.
  12.  
  13.     The basic routines can be recombined to achieve a variety
  14.     of effects.  (For example, instead of toggling, one FKey
  15.     could make the windows transparent and another restore them.
  16.     
  17.     Note that we do no error checking on the region calculations, 
  18.     so we could crash in low memory situations.
  19.     
  20.  
  21. Known Bugs:
  22.     • In MPW if you activate a transparent window, the  shell
  23.       computes the active region of the window.  Since the window
  24.       is transparent, the region is empty.  If you make the window
  25.       normal, the shell becomes confused until the window is activated
  26.       again.
  27.       
  28.       
  29. MPW Build commands (to make FKEY 9):
  30.  
  31.     Pascal Holey.p -o Holey.p.o 
  32.     link Holey.p.o -o 'Holey FKEY' -rt FKEY=9 -sn Main="Holey" ∂
  33.             -m 'ENTRYPOINT' -t 'FKEY' -c 'FKEY'
  34.             
  35. Larry Rosenstein
  36. *)
  37.  
  38. UNIT Holey;
  39.  
  40. INTERFACE
  41.  
  42. USES
  43.     MemTypes, Quickdraw, OSIntf, ToolIntf;
  44.     
  45. PROCEDURE EntryPoint;
  46.  
  47. IMPLEMENTATION
  48.  
  49. PROCEDURE HoleyFKey; FORWARD;
  50.  
  51.     { The main program.  We need this entry point here because
  52.         we use nested procedures.  Otherwise the nested procs
  53.         would be first in the segment. }
  54. PROCEDURE EntryPoint;
  55. BEGIN
  56.     HoleyFKey;
  57. END;
  58.  
  59. PROCEDURE HoleyFKey;
  60.  
  61.     VAR    w:                WindowPeek;
  62.         v:                INTEGER;
  63.         
  64.         savePort:        GrafPtr;
  65.         
  66.         topChange:        WindowPeek;    { topmost windows that changed }
  67.         clobber:        RgnHandle;    { union of all changed windows }
  68.     
  69.     PROCEDURE Setup;            { call this to setup things }
  70.     BEGIN
  71.             { Save the current port }
  72.         GetPort(savePort);
  73.         
  74.             { Init some variables }
  75.         topChange := NIL;
  76.         clobber := NewRgn;
  77.     END;
  78.     
  79.     PROCEDURE WrapUp;            { call this after munging the windows }
  80.     BEGIN
  81.         IF topChange <> NIL THEN { have system refresh things }
  82.             BEGIN
  83.             CalcVisBehind(topChange, clobber);    { cause update events }
  84.             PaintBehind(topChange, clobber);    { refresh window structures }
  85.             END;
  86.         
  87.         DisposeRgn(clobber);
  88.         
  89.         SetPort(savePort);
  90.     END;
  91.     
  92.     PROCEDURE NoteWindow(w: WindowPeek);        { remember info about window }
  93.     BEGIN
  94.         IF topChange = NIL THEN
  95.             topChange := w;
  96.             
  97.         UnionRgn(clobber, w^.strucRgn, clobber);
  98.     END;
  99.     
  100.     PROCEDURE MakeTransparent(w: WindowPeek);
  101.     BEGIN
  102.         WITH w^ DO    { windows are nonrelocatable }
  103.             IF visible THEN    { don't call this on invisible windows }
  104.                 BEGIN
  105.                 NoteWindow(w);
  106.             
  107.                 { make content rgn empty and fix structure rgn accordingly }
  108.                 DiffRgn(strucRgn, contRgn, strucRgn);
  109.                 SetEmptyRgn(contRgn);
  110.                 END;
  111.     END;
  112.     
  113.     PROCEDURE MakeNormal(w: WindowPeek);
  114.     BEGIN
  115.         IF w^.visible THEN    { don't call this on invisible windows }
  116.             BEGIN
  117.             WITH grafPtr(w)^.portRect DO
  118.                 SizeWindow(windowPtr(w), right-left, bottom-top, TRUE);
  119.             NoteWindow(w);
  120.             END;
  121.     END;
  122.     
  123.     
  124. BEGIN
  125.     Setup;
  126.     
  127.     w := WindowPeek(FrontWindow);
  128.     
  129.         { Loop through all the windows }
  130.     WHILE w <> NIL DO
  131.         BEGIN
  132.             IF EmptyRgn(w^.contRgn) THEN    { already transparent }
  133.                 MakeNormal(w)
  134.             ELSE                             { window is normal }
  135.                 MakeTransparent(w);
  136.                 
  137.             w := w^.nextWindow;
  138.         END;
  139.     
  140.     WrapUp;
  141. END;
  142.  
  143. END.
  144.